package com.codoon.unova.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector.OnGestureListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * @author scott
 *         Function:Activity基类
 */
public abstract class BaseActivity extends Activity implements OnClickListener, OnGestureListener {
	protected GestureDetector detector;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		detector = new GestureDetector(this);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		initView();
	}

	protected abstract void initView();

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	protected void changeView(Class targetClass, Bundle bundle) {
		Intent intent = new Intent(this, targetClass);
		if (null != bundle) {
			intent.putExtra("bundle", bundle);
		}
		startActivity(intent);
	}

	protected void changeView(Class targetClass, Bundle bundle, boolean isFinish) {
		Intent intent = new Intent(this, targetClass);
		if (null != bundle) {
			intent.putExtra("bundle", bundle);
		}
		startActivity(intent);
		if (isFinish) {
			this.finish();
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return this.detector.onTouchEvent(event);
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		if (e1.getX() - e2.getX() > 30) {
			showRight();
			return true;
		} else if (e1.getX() - e2.getX() < -30) {
			showLeft();
			return true;
		} else if (e1.getY() - e2.getY() > 30) {
			showNext();
			return true;
		} else if (e1.getY() - e2.getY() < -30) {
			showPrevious();
			return true;
		}
		return false;
	}

	/**
	 * 
	 * Function:显示上一个界面
	 */
	protected void showNext() {
	}

	/**
	 * 
	 * Function:显示下一个界面
	 */
	protected void showPrevious() {
	}

	/**
	 * 
	 * Function:显示左边的界面
	 */
	protected void showLeft() {
	}

	/**
	 * 
	 * Function:显示右边的界面
	 */
	protected void showRight() {
	}

	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

}
